package com.example.whatrubbish.service.impl;

import com.example.whatrubbish.mapper.FeedbackMapper;
import com.example.whatrubbish.model.Feedback;
import com.example.whatrubbish.service.FeedbackService;
import com.example.whatrubbish.vo.Criteria;
import com.example.whatrubbish.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    FeedbackMapper feedbackMapper;

    @Override
    public PageBean<Feedback> selectAllUnRead(Criteria criteria) {
        Long total = feedbackMapper.selectAllUnReadCount(criteria);
        List<Feedback> list = feedbackMapper.selectAllUnRead(criteria);
        PageBean<Feedback> pageBean = new PageBean(total, list);
        return pageBean;
    }

    @Override
    public PageBean<Feedback> selectAllRead(Criteria criteria) {
        Long total = feedbackMapper.selectAllReadCount(criteria);
        List<Feedback> list = feedbackMapper.selectAllRead(criteria);
        PageBean<Feedback> pageBean = new PageBean(total, list);
        return pageBean;
    }

    @Override
    public PageBean<Feedback> selectAllDelete(Criteria criteria) {
        Long total = feedbackMapper.selectAllDeleteCount(criteria);
        List<Feedback> list = feedbackMapper.selectAllDelete(criteria);
        PageBean<Feedback> pageBean = new PageBean(total, list);
        return pageBean;
    }

    @Override
    public int updateReadById(Long feedbackId) {
        return feedbackMapper.updateReadById(feedbackId);
    }

    @Override
    public int updateReadByList(List list) {
        return feedbackMapper.updateReadByList(list);
    }

    @Override
    public int deleteById(Long feedbackId) {
        return feedbackMapper.deleteById(feedbackId);
    }

    @Override
    public int deleteByList(List list) {
        return feedbackMapper.deleteByList(list);
    }

    @Override
    public int deleteByPrimaryKey(Long feedbackId) {
        return feedbackMapper.deleteByPrimaryKey(feedbackId);
    }

    @Override
    public int deleteByPrimaryKeyList(List list) {
        return feedbackMapper.deleteByPrimaryKeyList(list);
    }

    @Override
    public int insertSelective(Feedback record) {
        record.setFeedbackStatus(0);
        record.setFeedbackTime(new Date());
        return feedbackMapper.insertSelective(record);
    }
}
